package com.nf.health.app.adapter;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.nf.health.app.R;
import com.nf.health.app.activity.global.PictureActivity;
import com.nf.health.app.activity.my.bean.SweatQuestryModel;
import com.nf.health.app.glide.GlideUtil;
import com.nf.health.app.utils.ActivityUtils;

import java.util.ArrayList;

/**
 * Created by 恩福 on 2016/11/22.
 *
 * @auther changpeng
 * @email obj_cp@126.com
 */

public class ImageViewAdapter2 extends RecyclerView.Adapter<ImageViewAdapter2.MyViewHolder> {


    private SweatQuestryModel deviceDataBean;
    private Context context;
    private ArrayList<String> urls = null;

    public ImageViewAdapter2(Context context, SweatQuestryModel deviceDataBean) {
        this.context = context;
        this.deviceDataBean = deviceDataBean;
        initImageUrl(deviceDataBean);
    }

    private void initImageUrl(SweatQuestryModel deviceDataBean) {
        urls = new ArrayList<>();
        if(urls != null){
            urls.addAll(deviceDataBean.getList());
        }
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_imageview, null);
        MyViewHolder holder = new MyViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        GlideUtil.loadNetImg2(context, holder.image, urls.get(position) , R.drawable.default_square_image);
        holder.image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putStringArrayList("imgUrls",urls);
                bundle.putInt("position", position);
                bundle.putInt("type", PictureActivity.TYPE_NET_IMG);
                ActivityUtils.showActivity(context, PictureActivity.class, bundle);
            }
        });

    }


    @Override
    public int getItemCount() {
        return deviceDataBean == null ? 0 : 9;
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        ImageView image;

        public MyViewHolder(View itemView) {
            super(itemView);
            image = (ImageView) itemView.findViewById(R.id.sweat_recycler_image);
        }
    }
}
